package com.example.programme.home;



import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;
import android.os.Bundle;



import com.example.programme.MyPageAdapter;
import com.example.programme.R;
import com.example.programme.database.DBHelper;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;

public class HomeActivity extends AppCompatActivity {

    DBHelper dbHelper;
    ViewPager2 viewPager;
    public  static HomeActivity instance=null;

    //每个page的名字分别为 词库、查找、我的
    private static void onConfigureTab(TabLayout.Tab tab, int position) {
        switch (position) {
            case 0:
                tab.setIcon(R.drawable.ic_wordbase);//设置标题的图像
                tab.setText("词库");
                // viewPager.getCurrentItem(0);
                break;

            case 1:
                tab.setIcon(R.drawable.ic_search);
                tab.setText("查找");
                break;

            case 2:
                tab.setIcon(R.drawable.ic_mine);
                tab.setText("我的");
                break;
            default:
                break;

        }
        ;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        instance=this;//在修改密码后调用关闭HomeActivity
        //页面装配
        ViewPager2 viewPager = findViewById(R.id.viewPage2);
        MyPageAdapter pageAdapter = new MyPageAdapter(this);
        viewPager.setAdapter(pageAdapter);
        //控件访问
        TabLayout tabLayout = findViewById(R.id.tab_layout);
        new TabLayoutMediator(tabLayout, viewPager,
                HomeActivity::onConfigureTab).attach();//每个页面的标题匹配

        dbHelper = new DBHelper(HomeActivity.this);

    }
}